﻿namespace Morus
{
    using System;
    using System.Diagnostics;

    public static partial class GuidExtension
    {
        [DebuggerStepThrough]
        public static string Shrink(this Guid target)
        {
            Check.Argument.IsNotEmpty(target, "target");

            string base64 = Convert.ToBase64String(target.ToByteArray());
            string encoded = base64.Replace('/', '_').Replace('+', '-');
            return encoded.Substring(0, 22);
        }

        [DebuggerStepThrough]
        public static bool IsEmpty(this Guid target)
        {
            return target == Guid.Empty;
        }

        [DebuggerStepThrough]
        public static string GenShortString(this Guid target)
        {
            long i = 1;
            foreach (byte b in target.ToByteArray())
            {
                i *= ((int)b + 1);
            }
            return string.Format("{0:x}", i - DateTime.Now.Ticks);
        }
    }
}
